import time
import unittest
from page import Page
from ddt import file_data, ddt
import logging

@ddt
class MyTestCase(unittest.TestCase):
    # 打开
    def setUp(self):
        self.pg=Page()
    # #退出
    # def tearDown(self):
    #     self.pg.tui()
    # 步骤
    @file_data('test.json')
    def test_login(self,name,yuqi,case):
        try:
            # 强制等待
            time.sleep(3)
            # 点击首页搜索框
            self.pg.sousuo1().click()
        except Exception:
            logging.error('异常')
            self.pg.jie('yc.png')
        # 搜索框输入内容
        logging.info('搜索框输入内容')
        self.pg.sousuo2().send_keys(name)
        # 点击搜索按钮
        logging.info('点击搜索按钮')
        self.pg.sousuoanniu().click()
        # 点击价格
        logging.info('点击价格')
        self.pg.jiage().click()
        # 点击价格排序
        logging.info('点击价格排序')
        self.pg.jiapai().click()
        # 点击书籍图片
        logging.info('点击书籍图片')
        self.pg.tu().click()
        # 点击加入购物车
        logging.info('点击加入购物车')
        self.pg.jiagou().click()
        # 点击进入购物车
        logging.info('点击进入购物车')
        self.pg.jingou().click()
        # 断言
        # shiji=self.pg.duanyan().text
        # yuqi='购物车'
        # self.assertEqual(yuqi,shiji)
        if case==1:
            shiji=self.pg.duanyan().text
            self.assertEqual(yuqi, shiji)
        elif case==2:
            shiji = self.pg.duanyan().text
            self.assertEqual(yuqi, shiji)


if __name__ == '__main__':
    unittest.main()
